<script setup lang="ts">
import { getManageDataAPI } from '@/apis/rodManage';
import { PoleType } from '@/enums/rodManage';
import type { GetManageParamsType, ManageItemType } from '@/types/rodManage';
import { ref } from 'vue';

// 获取列表所需参数
const getManageParams = ref<GetManageParamsType>({
  page: 1, // 页码
  pageSize: 5, // 每页条数
  poleName: undefined, // 一体杆名称
  poleNumber: undefined, // 一体杆编号
  poleStatus: undefined // 运行状态 0:正常,1:异常
})

// 获取列表数据 --------------
const manageTotal = ref<number>(0) // 总条数
const manageList = ref<ManageItemType[]>() // 列表数据
const getManageData = async () => {
  const res = await getManageDataAPI(getManageParams.value)
  manageTotal.value = res.data.total
  manageList.value = res.data.rows
}
getManageData()

// 一体杆类型
const poleType = (row: ManageItemType) => {
  return row.poleType === PoleType.Entrance ? '入口' : '出口'
}
// 运行状态
const poleStatus = (row: ManageItemType) =>{
  return row.poleStatus === 0 ? '正常' : '异常'
}

</script>
<template>
<div class="card-container">
    <!-- 搜索区域 -->
    <div class="search-container">
      <span class="search-label">一体嘎名称：</span>
      <el-input v-model="getManageParams.poleName" @clear="getManageData()" placeholder="请输入一体杆名称" clearable class="search-main" />
      <span class="search-label">一体嘎编号：</span>
      <el-input v-model="getManageParams.poleNumber" @clear="getManageData()" placeholder="请输入一体嘎编号" clearable class="search-main" />
      <span class="search-label">运行状态状态：</span>
      <el-select v-model="getManageParams.poleStatus" @clear="getManageData()" placeholder="请选择运行状态" clearable style="width: 240px">
        <el-option label="正常" value="0" />
        <el-option label="异常" value="1" />
      </el-select>
      <el-button type="primary" class="search-btn" @click="getManageData()">查询</el-button>
    </div>
    <!-- 新增删除 -->
    <div class="create-container">
      <div class="left">
        <el-button type="primary">添加一体杆</el-button>
        <el-button>批量删除</el-button>
      </div>
    </div>
    <!-- 表格区域 -->
    <div class="table">
      <!-- @selection-change="onSelectionChange" -->
      <el-table style="width: 100%" :data="manageList">
        <el-table-column type="selection" />
        <el-table-column type="index" label="序号" width="60" align="center" />
        <el-table-column label="一体嘎名称" prop="poleName" />
        <el-table-column label="一体杆编号" prop="poleNumber" />
        <el-table-column label="一体杆IP" prop="poleIp" />
        <el-table-column label="安装区域" prop="areaName" />
        <el-table-column label="一体嘎类型" prop="poleType" :formatter="poleType" />
        <el-table-column label="运行状态" prop="poleStatus" :formatter="poleStatus" />
        <el-table-column label="操作" fixed="right">
          <template #default="{ row }">
            <el-button size="small" type="primary" link>编辑</el-button>
            <el-button size="small" type="primary" link>删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 分页 -->
    <div class="page-container">
      <el-pagination 
        layout="total, sizes, prev, pager, next"
        :total="manageTotal"
        :page-sizes="[2,5,10,20]"
        v-model:current-page="getManageParams.page"
        v-model:page-size="getManageParams.pageSize"
        @change="getManageData"
      />
    </div>
  </div>
</template>

<style lang="scss" scoped>
.card-container {
  padding: 20px;
  background-color: #fff;
}

.search-container {
  display: flex;
  align-items: center;
  border-bottom: 1px solid rgb(237, 237, 237, .9);
  padding-bottom: 20px;

  .search-main {
    width: 220px;
    margin-right: 10px;
  }

  .search-btn {
    margin-left: 20px;
  }
}

.create-container {
  display: flex;
  justify-content: space-between;
  margin: 20px 0px;
  .right {
    height: 35px;
    line-height: 35px;
    padding: 0px 10px;
    background-color: #e6f7ff;
    border: 1px solid #abdfff;
    border-radius: 5px;
    font-size: 13px;
    display: flex;
    align-items: center;
  }
}

.page-container {
  padding: 4px 0px;
  text-align: right;
}

.form-container {
  padding: 0px 80px;
}
</style>
